package com.team6.yygh.util;

import com.team6.yygh.helper.JwtHelper;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName AuthContextHolder
 * @Author ZhuYouWan
 * @Date 2022/10/25 19:38
 * 获取当前用户信息工具类
 **/
public class AuthContextHolder {

    /**
     * 获取当前用户id
     */
    public static Long getUserId(HttpServletRequest request) {
        // 从header获取token
        String token = request.getHeader("token");
        // 从jwt获取userId
        Long userId = JwtHelper.getUserId(token);
        return userId;
    }

    /**
     * 获取当前用户名称
     */
    public static String getUserName(HttpServletRequest request) {
        // 从header获取token
        String token = request.getHeader("token");
        // 从jwt获取userName
        String userName = JwtHelper.getUserName(token);
        return userName;
    }
}
